layui.define(['jquery', 'element', 'dropdown'], function (exports) {
	"use strict";

	var MOD_NAME = 'tabPage',
		$ = layui.jquery,
		dropdown = layui.dropdown,
		tabs = layui.tabs;

	var tabPage = function (opt) {
		this.option = opt;
	};

	var tabData = new Array();
	var tabDataCurrent = 0;
	var contextTabDOM;

	tabPage.prototype.render = function (opt) {

		var option = {
			elem: opt.elem,
			data: opt.data,
			index: opt.index,
			tool: opt.tool || true,
			roll: opt.roll || true,
			success: opt.success ? opt.success : function (id) { },
			session: opt.session ? opt.session : false,
			preload: opt.preload ? opt.preload : false,
			height: opt.height || "100%",
			width: opt.width || "100%",
			closeEvent: opt.closeEvent,
			tabMax: opt.tabMax,
		}

		if (option.session) {
			if (sessionStorage.getItem(option.elem + "-kav7-tab-page-data") != null) {
				tabData = JSON.parse(sessionStorage.getItem(option.elem + "-kav7-tab-page-data"));
				option.data = JSON.parse(sessionStorage.getItem(option.elem + "-kav7-tab-page-data"));
				tabDataCurrent = sessionStorage.getItem(option.elem + "-kav7-tab-page-data-current");
				tabData.forEach(function (item, index) {
					if (item.id == tabDataCurrent) {
						option.index = index;
					}
				})
			} else {
				tabData = opt.data;
			}
		}

		var lastIndex;
		var tab = createTab(option);
		$("#" + option.elem).html(tab);
		$(".layui-tabs[lay-filter='" + option.elem + "'] .layui-tabs-prev").click(function () {
			rollPage("left", option);
		})
		$(".layui-tabs[lay-filter='" + option.elem + "'] .layui-tabs-next").click(function () {
			rollPage("right", option);
		})
		tabs.render();
		$("#" + option.elem).width(opt.width);
		$("#" + option.elem).height(opt.height);
		$("#" + option.elem).css({
			position: "relative"
		});

		closeEvent(option);

		option.success(sessionStorage.getItem(option.elem + "-kav7-tab-page-data-current"));

		dropdown.render({
			elem: `#${option.elem} .layui-tabs-control > .layui-icon-down`,
			trigger: 'hover',
			data: [{
				title: '关 闭 当 前',
				id: 1
			}, {
				title: '关 闭 其 他',
				id: 2
			}, {
				title: '关 闭 全 部',
				id: 3
			}],
			click: function (obj) {
				const id = obj.id;
				if (id === 1) {
					var currentTab = $(".layui-tabs[lay-filter='" + option.elem + "'] .kaTabMenu .layui-this");
					if (currentTab.find("span").is(".able-close")) {
						var currentId = currentTab.attr("lay-id");
						tabDelete(option.elem, currentId, option.closeEvent, option);
					} else {
						kaMsg.error({ "code": 1000, "msg": "当前页面不允许关闭" });
					}
				} else if (id === 2) {
					var currentId = $(".layui-tabs[lay-filter='" + option.elem + "'] .kaTabMenu .layui-this").attr("lay-id");
					var tabtitle = $(".layui-tabs[lay-filter='" + option.elem + "'] .kaTabMenu li");
					$.each(tabtitle, function (i) {
						if ($(this).attr("lay-id") != currentId) {
							if ($(this).find("span").is(".able-close")) {
								tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent,
									option);
							}
						}
					})
				} else {
					var currentId = $(".layui-tabs[lay-filter='" + option.elem +
						"'] .kaTabMenu .layui-this").attr("lay-id");
					var tabtitle = $(".layui-tabs[lay-filter='" + option.elem + "'] .kaTabMenu li");
					$.each(tabtitle, function (i) {
						if ($(this).find("span").is(".able-close")) {
							tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent, option);
						}
					})
				}

			}
		})

		$("body .layui-tabs[lay-filter='" + option.elem + "'] .kaTabMenu").on("contextmenu", "li",
			function (e) {
				var top = e.clientY;
				var left = e.clientX;
				var menuWidth = 150;
				var menu = `<ul>
								<li class='item kav7ulli' id='${option.elem}closeThis'>
									<div class="kav7ulliDiv">
										<i class="layui-icon layui-icon-error"></i>
										<span> 关 闭 当 前 </span> 
									</div>
								</li>
								<li class='item kav7ulli' id='${option.elem}closeOther'>
									<div class="kav7ulliDiv">
										<i class="layui-icon layui-icon-error"></i>
										<span> 关 闭 其 他 </span> 
									</div>
								</li>
								<li class='item kav7ulli' id='${option.elem}closeLeft'>
									<div class="kav7ulliDiv">
										<i class="layui-icon layui-icon-error"></i>
										<span> 关 闭 左 边 </span> 
									</div>
								</li>
								<li class='item kav7ulli' id='${option.elem}closeRight'>
									<div class="kav7ulliDiv">
										<i class="layui-icon layui-icon-error"></i>
										<span> 关 闭 右 边 </span> 
									</div>
								</li>
								<li class='item kav7ulli' id='${option.elem}closeAll'>
									<div class="kav7ulliDiv">
										<i class="layui-icon layui-icon-error"></i>
										<span> 关 闭 所 有 </span> 
									</div>
								</li>
								<li class='item kav7ulli' id='${option.elem}doBrowser'>
									<div class="kav7ulliDiv">
										<i class="layui-icon layui-icon-ie"></i>
										<span> 浏 览 器 打 开 </span> 
									</div>
								</li>
								<li class='item kav7ulli' id='${option.elem}addKJfs'>
									<div class="kav7ulliDiv">
										<i class="layui-icon layui-icon-success"></i>
										<span> 添 加 快 捷 方 式 </span> 
									</div>
								</li>
							</ul>`
					;
				contextTabDOM = $(this);
				var isOutsideBounds = (left + menuWidth) > $(window).width();
				if (isOutsideBounds) {
					left = $(window).width() - menuWidth;
				}

				layer.open({
					type: 1,
					title: false,
					shade: false,
					skin: 'pear-tab-page-menu',
					closeBtn: false,
					area: [menuWidth + 'px', '245px'],
					fixed: true,
					anim: false,
					isOutAnim: false,
					offset: [top, left],
					content: menu,
					success: function (layero, index) {
						layer.close(lastIndex);
						lastIndex = index;
						menuEvent(option, index);
						var timer;
						$(layero).on('mouseout', function () {
							timer = setTimeout(function () {
								layer.close(index);
							}, 30)
						});

						$(layero).on('mouseover', function () {
							clearTimeout(timer);
						});

						$(layero).on('contextmenu', function () {
							return false;
						})
					}
				});
				return false;
			}
		)

		mousewheelAndTouchmoveHandler(option)
		return new tabPage(option);
	}

	tabPage.prototype.click = function (callback) {
		var option = this.option;
		var elem = this.option.elem;
		tabs.on('afterChange(' + this.option.elem + 'Tabs)', function(data) {
			var id = $("#" + elem + " .kaTabMenu .layui-this").attr("lay-id");
			sessionStorage.setItem(option.elem + "-kav7-tab-page-data-current", id);
			callback(id);
		});
	}

	tabPage.prototype.positionTab = function () {
		var $tabTitle = $('.layui-tabs[lay-filter=' + this.option.elem + ']  .kaTabMenu');
		var autoLeft = 0;
		$tabTitle.children("li").each(function () {
			if ($(this).hasClass('layui-this')) {
				return false;
			} else {
				autoLeft += $(this).outerWidth();
			}
		});
		$tabTitle.animate({
			scrollLeft: autoLeft - $tabTitle.width() / 3
		}, 200);
	}

	tabPage.prototype.clear = function () {
		sessionStorage.removeItem(this.option.elem + "-kav7-tab-page-data");
		sessionStorage.removeItem(this.option.elem + "-kav7-tab-page-data-current");
	}

	tabPage.prototype.changeTabTitleById = function (id, title) {
		var currentTab = $(".layui-tabs[lay-filter='" + this.option.elem + "'] .kaTabMenu [lay-id='" + id + "'] .title");
		currentTab.html(title);
	}

	/**
	 * @since KA Admin 7.0
	 * 
	 * 删除指定选项卡
	 * 
	 * @param id 编号
	 */
	tabPage.prototype.removeTab = function (id) {
		var elem = this.option.elem;
		if (id != undefined) {
			var currentTab = $(".layui-tabs[lay-filter='" + elem + "'] .kaTabMenu [lay-id='" + id + "']");
			if (currentTab.find("span").is(".able-close")) {
				tabDelete(elem, id, () => { });
			}
		} else {
			var tabtitle = $(".layui-tabs[lay-filter='" + elem + "'] .kaTabMenu li");
			$.each(tabtitle, function () {
				if ($(this).find("span").is(".able-close")) {
					tabDelete(elem, $(this).attr("lay-id"), () => { });
				}
			})
		}
	}

	/**
	 * @since KA Admin 7.0
	 * 
	 * 删除其他选项卡
	 */
	tabPage.prototype.removeOtherTab = function () {
		var elem = this.option.elem;
		var currentId = $(".layui-tabs[lay-filter='" + elem + "'] .kaTabMenu .layui-this").attr("lay-id");
		var tabtitle = $(".layui-tabs[lay-filter='" + elem + "'] .kaTabMenu li");
		$.each(tabtitle, function () {
			if ($(this).attr("lay-id") != currentId) {
				if ($(this).find("span").is(".able-close")) {
					tabDelete(elem, $(this).attr("lay-id"), () => { });
				}
			}
		})
	}

	/**
	 * @since KA Admin 7.0
	 * 
	 * 删除选中选项卡
	 */
	tabPage.prototype.removeCurrentTab = function () {
		var currentTab = $(".layui-tabs[lay-filter='" + this.option.elem + "'] .kaTabMenu .layui-this");
		if (currentTab.find("span").is(".able-close")) {
			var currentId = currentTab.attr("lay-id");
			tabDelete(this.option.elem, currentId, () => { });
		}
	}

	/**
	 * @since KA Admin 7.0
	 * 
	 * 切换选项卡
	 * 
	 * @param opt 内容
	 */
	tabPage.prototype.changePage = function (opt) {
		kalog.outLogs(["菜单日志x：", opt]);
		var option = kaValue.getUrl("addAndUpdateMenucommon");
		option.url = option.url;
		option.async = false;
		option.data = {
			menuId: opt.id
		}
		option.success = function (re) {
			if (re.code == 200) {
				if (opt.callback != undefined && opt.callback != null && opt.callback != "") {
					opt.callback(re);
				}
			}
		}
		ka.ajax(option);
		var title = `<span class="kav7-tab-page-active"></span>
					 <span class="${opt.close ? 'able-close' : 'disable-close'} title">${opt.title}</span>
					 <i class="layui-icon layui-unselect layui-tabs-close">ဆ</i>`;

		if ($(".layui-tabs[lay-filter='" + this.option.elem + "'] .kaTabMenu li[lay-id]").length <=
			0) {
			var that = this;
			if (opt.type === "_iframe") {
				tabs.add(this.option.elem + "Tabs", {
					id: opt.id,
					title: title,
					content: `<iframe id="${opt.id}" type="${opt.type}" data-frameid="${opt.id}" scrolling="auto" frameborder="0" src="${opt.url}" style="width:100%;" allowfullscreen="true"></iframe>`
				});

			} else {

				$.ajax({
					url: opt.url,
					type: 'get',
					dataType: 'html',
					async: false,
					success: function (data) {
						tabs.add(that.option.elem + "Tabs", {
							id: opt.id,
							title: title,
							content: `<div id="${opt.id}" type="${opt.type}" data-frameid="${opt.id}" src="${opt.url}">${data}</div>`,
						});
					},
					error: function (xhr, textstatus, thrown) {
						return layer.msg('Status:' + xhr.status + '，' + xhr.statusText + '，请稍后再试！');
					}
				});
			}

			tabData.push(opt);
			sessionStorage.setItem(that.option.elem + "-kav7-tab-page-data", JSON.stringify(tabData));
			sessionStorage.setItem(that.option.elem + "-kav7-tab-page-data-current", opt.id);

		} else {

			var isData = false;
			$.each($(".layui-tabs[lay-filter='" + this.option.elem + "'] .kaTabMenu li[lay-id]"),
				function () {
					if ($(this).attr("lay-id") == opt.id) {
						isData = true;
					}
				})

			if (isData == false) {

				if (this.option.tabMax != false) {
					if ($(".layui-tabs[lay-filter='" + this.option.elem + "'] .kaTabMenu li[lay-id]")
						.length >= this.option.tabMax) {
						layer.msg("最多打开" + this.option.tabMax + "个标签页", {
							icon: 2,
							time: 1000,
							shift: 6
						});
						return false;
					}
				}

				var that = this;
				if (opt.type === "_iframe") {
					tabs.add(this.option.elem + "Tabs", {
						id: opt.id,
						title: title,
						content: `<iframe id="${opt.id}" type="${opt.type}" data-frameid="${opt.id}" scrolling="auto" frameborder="0" src="${opt.url}" style="width:100%;height:100%;" allowfullscreen="true"></iframe>`
					});
				} else {
					$.ajax({
						url: opt.url,
						type: 'get',
						dataType: 'html',
						async: false,
						success: function (data) {
							tabs.add(that.option.elem + "Tabs", {
								id: opt.id,
								title: title,
								content: `<div id="${opt.id}" type="${opt.type}" data-frameid="${opt.id}" src="${opt.url}">${data}</div>`,
							});
						},
						error: function (xhr, textstatus, thrown) {
							return layer.msg('Status:' + xhr.status + '，' + xhr.statusText + '，请稍后再试！');
						}
					});
				}
				tabData.push(opt);
				sessionStorage.setItem(that.option.elem + "-kav7-tab-page-data", JSON.stringify(tabData));
				sessionStorage.setItem(that.option.elem + "-kav7-tab-page-data-current", opt.id);
			}
		}
		tabs.change(this.option.elem + "Tabs", opt.id);
		sessionStorage.setItem(this.option.elem + "-kav7-tab-page-data-current", opt.id);
	}

	/**
	 * 刷新当前选型卡
	 * 
	 * @param time 动画时长
	 */
	tabPage.prototype.refresh = function (time) {
		var $iframe = $(".layui-tabs[lay-filter='" + this.option.elem + "']>.layui-tabs-body>.layui-show>*");
		var $iframeLoad;

		if (time != false && time != 0) {
			$iframeLoad = $("#" + this.option.elem).find(".kav7-tab-page-loading");
			$iframeLoad.css({
				display: "block"
			});
		}
		if ($iframe.attr("type") === "_iframe") {
			$iframe.attr("src", $iframe.attr("src"));
			tabs.refresh("" + this.option.elem + "Tabs");
			$iframe.on("load", function () {
				$iframeLoad.fadeOut(1000, function () {
					$iframeLoad.css({
						display: "none"
					});
				});
			})
		} else {
			var optionelem = this.option.elem;
			$.ajax({
				url: $iframe.attr("src"),
				type: 'get',
				dataType: 'html',
				success: function (data) {
					// $iframe.html(data);
					tabs.refresh("" + optionelem + "Tabs");
					if ($iframeLoad != undefined) {
						$iframeLoad.fadeOut(1000, function () {
							$iframeLoad.css({
								display: "none"
							});
						});
					}
				},
				error: function (xhr) {
					return layer.msg('Status:' + xhr.status + '，' + xhr.statusText + '，请稍后再试！');
				}
			});
		}
	}

	function tabDelete(elem, id, callback) {
		var tabTitle = $(".layui-tabs[lay-filter='" + elem + "']").find(".kaTabMenu");
		var removeTab = tabTitle.find("li[lay-id='" + id + "']");
		var nextNode = removeTab.next("li");
		if (!removeTab.hasClass("layui-this")) {
			removeTab.remove();
			var tabContent = $(".layui-tabs[lay-filter='" + elem + "']").find("*[id='" + id + "']")
				.parent();
			tabContent.remove();

			tabData = JSON.parse(sessionStorage.getItem(elem + "-kav7-tab-page-data"));
			tabDataCurrent = sessionStorage.getItem(elem + "-kav7-tab-page-data-current");
			tabData = tabData.filter(function (item) {
				return item.id != id;
			})
			sessionStorage.setItem(elem + "-kav7-tab-page-data", JSON.stringify(tabData));
			return false;
		}

		var currId;
		if (nextNode.length) {
			nextNode.addClass("layui-this");
			currId = nextNode.attr("lay-id");
			$("#" + elem + " [id='" + currId + "']").parent().addClass("layui-show");
		} else {
			var prevNode = removeTab.prev("li");
			prevNode.addClass("layui-this");
			currId = prevNode.attr("lay-id");
			$("#" + elem + " [id='" + currId + "']").parent().addClass("layui-show");
		}
		callback(currId);
		tabData = JSON.parse(sessionStorage.getItem(elem + "-kav7-tab-page-data"));
		tabDataCurrent = sessionStorage.getItem(elem + "-kav7-tab-page-data-current");
		tabData = tabData.filter(function (item) {
			return item.id != id;
		})
		sessionStorage.setItem(elem + "-kav7-tab-page-data", JSON.stringify(tabData));
		sessionStorage.setItem(elem + "-kav7-tab-page-data-current", currId);
		removeTab.remove();
		var tabContent = $(".layui-tabs[lay-filter='" + elem + "']").find("*[id='" + id + "']").parent();
		tabContent.remove();
	}

	/**
	 * @since KA Admin 7.0
	 */
	function createTab(option) {

		var type = "";
		if (option.roll == true) {
			type = "layui-tabs-roll";
		}
		if (option.tool != false) {
			type = "layui-tabs-tool";
		}
		if (option.roll == true && option.tool != false) {
			type = "layui-tabs-rollTool";
		}
		var tab = '<div class="kav7-tab-page ' + type + ' layui-tabs" id="' + option.elem + 'Tabs" lay-filter="' + option.elem + '" lay-options="{closable: true}" lay-allowClose="true">';
		var headers = '<ul class="layui-tabs-header kaTabMenu">';
		var content = '<div class="layui-tabs-body 666">';
		var loading = '<div class="kav7-tab-page-loading"><div class="ball-loader"><span></span><span></span><span></span><span></span></div></div>'
		var control = `<div class="layui-tabs-control">
							<li class="layui-tabs-prev layui-icon layui-icon-left"></li>
							<li class="layui-tabs-next layui-icon layui-icon-right"></li>
							<li class="layui-tabs-tool layui-icon layui-icon-down"></li>
						</div>`;

		// 处 理 选 项 卡 头 部
		var index = 0;

		$.each(option.data, function (i, item) {

			var titleItem = `<li lay-id="${item.id}" class="${option.index == index ? 'layui-this' : ''}">
								<span class="kav7-tab-page-active"></span>
								<span class="${item.close ? 'able-close' : 'disable-close'} title">
									${item.title}
								</span>
                                <i class="layui-icon layui-unselect layui-tabs-close">ဆ</i></li>
							</li>`;

			headers += titleItem;

			if (item.type === "_iframe") {

				content += `<div class="${option.index == index ? 'layui-show' : ''} layui-tabs-item"><iframe id="${item.id}" type="${item.type}" data-frameid="${item.id}" scrolling="auto" frameborder="0" src="${item.url}" style="width:100%;height:100%;" allowfullscreen="true"></iframe></div>`

			} else {

				$.ajax({
					url: item.url,
					type: 'get',
					dataType: 'html',
					async: false,
					success: function (data) {
						content += `<div class="${option.index == index ? 'layui-show' : ''} layui-tabs-item"><div id="${item.id}" type="${item.type}" data-frameid="${item.id}"  src="${item.url}">${data}</div></div>`;
					},
					error: function (xhr) {
						return layer.msg('Status:' + xhr.status + '，' + xhr.statusText + '，请稍后再试！');
					}
				});
			}

			index++;
		});

		headers += '</ul>';
		content += '</div>';

		tab += headers;
		tab += control;
		tab += content;
		tab += loading;
		tab += '</div>';
		tab += ''
		return tab;
	}

	function rollPage(d, option) {
		var $tabTitle = $('#' + option.elem + '  .kaTabMenu');
		var left = $tabTitle.scrollLeft();
		if ('left' === d) {
			$tabTitle.animate({
				scrollLeft: left - 450
			}, 200);
		} else {
			$tabTitle.animate({
				scrollLeft: left + 450
			}, 200);
		}
	}

	function closeEvent(option) {
		$(".layui-tabs[lay-filter='" + option.elem + "']").on("click", ".layui-tabs-close", function () {
			var layid = $(this).parent().attr("lay-id");
			tabDelete(option.elem, layid, option.closeEvent, option);
		})
		.on("mousedown", ".kaTabMenu li", function (e) {
			if (e.buttons === 4 && $(this).find("span").is(".able-close")) {
				tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent, option);
			}
		});
	}

	function menuEvent(option, index) {
		$("#" + option.elem + "closeThis").click(function () {
			var currentTab = contextTabDOM;
			if (currentTab.find("span").is(".able-close")) {
				var currentId = currentTab.attr("lay-id");
				tabDelete(option.elem, currentId, option.closeEvent, option);
			} else {
				kaMsg.error({ "code": 1000, "msg": "当前页面不允许关闭" });
			}
			layer.close(index);
		})

		$("#" + option.elem + "closeOther").click(function () {
			var currentId = contextTabDOM.attr("lay-id");
			var tabtitle = $(".layui-tabs[lay-filter='" + option.elem + "'] .kaTabMenu li");
			$.each(tabtitle, function (i) {
				if ($(this).attr("lay-id") != currentId) {
					if ($(this).find("span").is(".able-close")) {
						tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent,
							option);
					}
				}
			})
			layer.close(index);
		})

		$("#" + option.elem + "closeLeft").click(function () {
			var currentId = contextTabDOM.attr("lay-id");
			var tabtitle = $(".layui-tabs[lay-filter='" + option.elem + "'] .kaTabMenu li");
			var number = 0;
			$.each(tabtitle, function (i) {
				if ($(this).attr("lay-id") == currentId) {
					number = i
				}
			})
			$.each(tabtitle, function (i) {
				if (i < number) {
					if ($(this).find("span").is(".able-close")) {
						tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent,
							option);
					}
				}
			})
			layer.close(index);
		})

		$("#" + option.elem + "closeRight").click(function () {
			var currentId = contextTabDOM.attr("lay-id");
			var tabtitle = $(".layui-tabs[lay-filter='" + option.elem + "'] .kaTabMenu li");
			var number = 0;
			$.each(tabtitle, function (i) {
				if ($(this).attr("lay-id") == currentId) {
					number = i
				}
			})
			$.each(tabtitle, function (i) {
				if (i > number) {
					if ($(this).find("span").is(".able-close")) {
						tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent,
							option);
					}
				}
			})
			layer.close(index);
		})

		$("#" + option.elem + "closeAll").click(function () {
			var tabtitle = $(".layui-tabs[lay-filter='" + option.elem + "'] .kaTabMenu li");
			$.each(tabtitle, function (i) {
				if ($(this).find("span").is(".able-close")) {
					tabDelete(option.elem, $(this).attr("lay-id"), option.closeEvent, option);
				}
			})
			layer.close(index);
		})

		$("#" + option.elem + "doBrowser").click(function () {
			var currentId = contextTabDOM.attr("lay-id");
			var currentId = contextTabDOM.attr("lay-id");
			var f = $("#" + currentId).attr("src");
			window.open(f, "_blank")
		})
	}

	function mousewheelAndTouchmoveHandler(option) {
		var $bodyTab = $("body .layui-tabs[lay-filter='" + option.elem + "'] .kaTabMenu")
		var $tabTitle = $('#' + option.elem + '  .kaTabMenu');
		var mouseScrollStep = 100
		// 鼠标滚轮
		$bodyTab.on("mousewheel DOMMouseScroll", function (e) {
			e.originalEvent.preventDefault()
			var delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? "top" :
				"down")) || // chrome & ie
				(e.originalEvent.detail && (e.originalEvent.detail > 0 ? "down" : "top")); // firefox
			var scrollLeft = $tabTitle.scrollLeft();

			if (delta === "top") {
				scrollLeft -= mouseScrollStep
			} else if (delta === "down") {
				scrollLeft += mouseScrollStep
			}
			$tabTitle.scrollLeft(scrollLeft)
		});

		// 触摸移动
		var touchX = 0;
		$bodyTab.on("touchstart", function (e) {
			var touch = e.originalEvent.targetTouches[0];
			touchX = touch.pageX
		})

		$bodyTab.on("touchmove", function (e) {
			var event = e.originalEvent;
			if (event.targetTouches.length > 1) return;
			event.preventDefault();
			var touch = event.targetTouches[0];
			var distanceX = touchX - touch.pageX
			var scrollLeft = $tabTitle.scrollLeft();
			touchX = touch.pageX
			$tabTitle.scrollLeft(scrollLeft += distanceX)
		});
	}

	exports(MOD_NAME, new tabPage());
})
